package com.woniuxy.project115.kaer.tenant.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.project115.kaer.tenant.dto.ApplicationAttachmentDto;
import com.woniuxy.project115.kaer.tenant.entity.ApplicationAttachment;
import com.woniuxy.project115.kaer.tenant.mapper.ApplicationAttachmentMapper;
import com.woniuxy.project115.kaer.tenant.service.ApplicationAttachmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author HuH
 * @since 2025年02月17日
 */
@Service
public class ApplicationAttachmentServiceImpl extends ServiceImpl<ApplicationAttachmentMapper, ApplicationAttachment> implements ApplicationAttachmentService {
    @Resource
    private ApplicationAttachmentMapper applicationAttachmentMapper;

    @Override
    public List<ApplicationAttachmentDto> getAttachmentById(Integer applicationId) throws Exception {

        List<ApplicationAttachment> list = applicationAttachmentMapper.selectList(
                new QueryWrapper<ApplicationAttachment>().eq("application_id", applicationId)
        );
        ArrayList<ApplicationAttachmentDto> dtos = new ArrayList<>();
        for (ApplicationAttachment attachment : list) {
            ApplicationAttachmentDto dto = BeanUtil.toBean(attachment, ApplicationAttachmentDto.class);
            dtos.add(dto);
        }
        return dtos;
    }
}
